﻿using Loaf.自定义控件.Common;
using System.Windows;
using System.Windows.Controls;

namespace Loaf.自定义控件.Controls
{
    public class SymbolIcon : Control
    {
        /*
         * https://icomoon.io/app/#/select
         * 可以制作字体图标
         */
        public static readonly DependencyProperty IconProperty = DependencyProperty.Register(nameof(Icon),
            typeof(IconEnum), typeof(SymbolIcon), new PropertyMetadata(IconEnum.Empty, OnIconChanged));

        public static readonly DependencyProperty RawIconProperty = DependencyProperty.Register(nameof(RawIcon),
            typeof(string), typeof(SymbolIcon), new PropertyMetadata(null));

        public IconEnum Icon
        {
            get => (IconEnum)GetValue(IconProperty);
            set
            {
                SetValue(IconProperty, value);
            }
        }

        public string RawIcon
        {
            get => (string)GetValue(RawIconProperty);
            set => SetValue(RawIconProperty, value);
        }

        private static void OnIconChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs eventArgs)
        {
            if (dependency is not SymbolIcon control)
                return;
            if (control.Icon == IconEnum.Empty)
                control.RawIcon = Convert.ToChar(((int)IconEnum.Empty)).ToString();
            else
                control.RawIcon = Convert.ToChar(((int)control.Icon)).ToString();
        }
    }
}
